package com.tender;

import com.tender.utils.ESOperationTemplate;
import org.elasticsearch.action.get.GetRequest;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.client.RequestOptions;

public class A_6_GetDoc {

    public static void main(String[] args) throws Exception {
        ESOperationTemplate.process(client -> {

            try {
                GetRequest getRequest = new GetRequest();
                getRequest.index("user2").id("1001");

                GetResponse response = client.get(getRequest, RequestOptions.DEFAULT);
                // 打印结果信息
                System.out.println("_index:" + response.getIndex());
                System.out.println("_type:" + response.getType());
                System.out.println("_id:" + response.getId());
                System.out.println("source:" + response.getSourceAsString());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            return null;
        });
    }
}
